(function(){"use strict";BX.namespace("BX.Main");var e;var t;var i=JSON.stringify({owner:"Bitrix, Inc.",version:"2.1",enterprise_license:false,available_actions:["magic","filter","transform","sticker","text","adjustments","brush","focus","frames","camera"],features:["adjustment","filter","focus","overlay","transform","text","sticker","frame","brush","camera","library","export"],platform:"HTML5",app_identifiers:[],api_token:"QbbG4guiONSDiVtWkcvw8A",domains:["https://api.photoeditorsdk.com"],issued_at:1534847608,expires_at:null,signature:"QgxAUoamxsnyqgFEQIoyj7168MituWvgVbj8VIr5EBjVG0HZSBmDh3XLU+u3NWTC2GUiZ6FB9GGB0Otf6mZ4VlhiXtyE4Xf61tE+PiFt4LPjGlAURCGl1yT9oGVBdWgb8lu8QhZ224g4TmPzNBeA5lDZwOaS/ESOZjltp0T5RE70NMpSPkSj8HEgO5zX2LnBt0kBpVj7xGxiprFzSn8P30m8+9IX0OuwGJ4AJZnLOB97pz1V1/I50RUgyvRDh7esZ/GdqkewRoGUwkybqHC2oQH15koZThKnEJZ9ufw1JyNVeUDmNvDysDdiLh/zGFgx3yVrBzAxfDAMnQhPpHUhgSlOh1W1YA3TKU7itR2vbXs7sd0syUCvAYMHMjgfUvCBfUKG5d2GOhg1jvd3a+wuVeloTEGwWFnhCpuoY7fHc991inKKCfH4EG4aeAJ5dLnFsZznyOxKMTOWMlmsVMRpW5tjNHP9nSDlj5s5XBX2XVVDkp2gj3oU2znUGY/uc8lczDvHpx7s9PRd7lp5U16QMOXujWWY9iYraNzwyqa2mUrxDhS/PSrlgd8F39iadeIE8bJQHLTVZjlanVZEJwx19MuGEBnYc5SWPkauhVCXFhdlrLj2zIzd1KYEEs1sbMQ4H/IVszF9mHBGJXSZCdOweXiWVHeg0o9UvSyS/sVwZjw="});BX.Main.ImageEditor=function(e){this.predefinedOptions=e||{};this.popup=new BX.PopupWindow("image-editor-"+BX.util.getRandomString(),null,{zIndex:900,width:window.innerWidth-10,height:window.innerHeight-10,overlay:.9,noAllPaddings:true,className:"main-image-editor",animationOptions:{show:{className:"main-image-editor-show",eventType:"animation"},close:{className:"main-image-editor-close",eventType:"animation"}},events:{onPopupClose:this.onPopupClose.bind(this)}});this.loader=new BX.Loader;BX.bind(window,"resize",this.onWindowResize.bind(this))};BX.Main.ImageEditor.ratio={CUSTOM:"imgly_transform_common_custom",SQUARE:"imgly_transform_common_square","4/3":"imgly_transform_common_4-3","16/9":"imgly_transform_common_16-9",PROFILE:"imgly_transform_facebook_profile",FB_AD:"imgly_transform_facebook_ad",FB_POST:"imgly_transform_facebook_post",FB_COVER:"imgly_transform_facebook_cover"};BX.Main.ImageEditor.renderType={BASE64:"data-url",IMAGE:"image",BUFFER:"buffer",BLOB:"blob",MSBLOB:"ms-blob"};function o(e,t,o){var n="/bitrix/js/main/imageeditor/external/photoeditorsdk/assets";var s=t.forceCrop||false;var r={library:false};if(BX.type.isPlainObject(o)&&BX.type.isPlainObject(o.controlsOptions)){r=o.controlsOptions}if(BX.type.isPlainObject(t.controlsOptions)){r=Object.assign(r,t.controlsOptions);if(BX.type.isPlainObject(r.transform)&&BX.type.isArray(r.transform.categories)){r.transform.categories.forEach(function(e){if(BX.type.isArray(e.ratios)){e.ratios.forEach(function(e){if(BX.type.isPlainObject(e)&&BX.type.isPlainObject(e.dimensions)){var t=e.dimensions;e.dimensions=new PhotoEditorSDK.Math.Vector2(t.width,t.height)}})}})}}var a={type:BX.Main.ImageEditor.renderType.BASE64,download:false};if(BX.type.isPlainObject(o)&&BX.type.isPlainObject(o.export)){a=o.export}if(BX.type.isPlainObject(t.export)){a=Object.assign({},a,t.export)}var p=30;if(BX.type.isNumber(t.megapixels)){p=t.megapixels}var l="";if(BX.type.isString(t.defaultControl)){l=t.defaultControl}return new PhotoEditorSDK.UI.DesktopUI({container:t.container,license:i,assets:Object.assign({},{baseUrl:n},t.assets||{}),showHeader:false,responsive:true,preloader:false,versionCheck:false,logLevel:"error",language:"ru",editor:{preferredRenderer:"canvas",maxMegaPixels:{desktop:p},forceCrop:s,displayCloseButton:true,image:e,export:a,controlsOptions:r,defaultControl:l},extensions:{languages:{ru:BX.Main.ImageEditorLocale}}})}function n(e,t){return new Promise(function(i,o){if(typeof e==="string"){var n=e;e=new Image;if(!!t&&BX.type.isString(t)){e.src=BX.util.add_url_param(t,{sessid:BX.bitrix_sessid(),url:n})}else{e.src=n}}if(typeof e==="object"&&e instanceof Image){if(e.complete){i(e);return}e.onload=i.bind(null,e);e.onerror=o}})}function s(e){return(""+e).split("/").pop()}BX.Main.ImageEditor.getInstance=function(){return BX.Main.ImageEditor.instance||(BX.Main.ImageEditor.instance=new BX.Main.ImageEditor)};BX.Main.ImageEditor.prototype={edit:function(i){var s;if(BX.type.isPlainObject(i)){s=i.image;delete i.image}else{s=i}if(!s){throw new Error("Image should be a instance of Image or string path")}i=BX.type.isPlainObject(i)?i:{};i.container=this.popup.contentContainer;this.popup.show();document.documentElement.style.overflow="hidden";BX.onCustomEvent(this,"BX.Main.ImageEditor:show",[this]);var r=i.proxy||this.predefinedOptions.proxy;this.loader.show(this.popup.popupContainer);return n(s,r).then(function(n){var s=["main.imageeditor.external.react.production","main.imageeditor.external.photoeditorsdk"];BX.loadExt(s).then(function(){t=n;this.SDKInstance=o(n,i,this.predefinedOptions);this.SDKInstance.on("export",BX.proxy(this.onExport,this));this.SDKInstance.on("close",BX.proxy(this.popup.close,this.popup));this.loader.hide()}.bind(this));return new Promise(function(t){e=t})}.bind(this)).catch(function(){this.loader.hide();this.popup.setContent(this.createErrorMessage());return Promise.reject()}.bind(this))},createErrorMessage:function(){return BX.create("div",{props:{className:"main-image-editor-error"},children:[BX.create("div",{props:{className:"main-image-editor-error-text"},html:BX.message("IMAGE_EDITOR_POPUP_ERROR_MESSAGE_TEXT")}),BX.create("div",{children:[BX.create("button",{props:{className:"ui-btn"},text:BX.message("IMAGE_EDITOR_CLOSE_POPUP"),events:{click:function(){this.popup.close()}.bind(this)}})]})]})},apply:function(){this.SDKInstance.export()},close:function(){this.popup.close()},onPopupClose:function(){if(this.SDKInstance){this.SDKInstance.off("export",BX.proxy(this.onExport,this));this.SDKInstance.off("close",BX.proxy(this.popup.close,this.popup));this.SDKInstance.dispose()}this.popup.contentContainer.innerHTML="";document.documentElement.style.overflow=null;BX.onCustomEvent(this,"BX.Main.ImageEditor:close",[this])},onExport:function(i,o){if(o.getOptions().editor.export.type===BX.Main.ImageEditor.renderType.BASE64){var n=s(t.src);var r=i.split(",");var a=r[1];var p=r[0].match(new RegExp("data:image/(.*);base64"))[1];p=p==="jpeg"?"jpg":p;n=n.replace(/\.[^\.]+$/,"."+p);i=[n,a]}e(i);this.popup.close()},onWindowResize:function(){this.popup.setWidth(window.innerWidth-10);this.popup.setHeight(window.innerHeight-10)}}})();
//# sourceMappingURL=editor.map.js